package com.xjrh.traintravel.collector.api;

import com.xjrh.common.core.web.AjaxResult;
import com.xjrh.traintravel.collector.api.param.Equipment;
import com.xjrh.traintravel.collector.netty.command.check.CheckData;
import com.xjrh.traintravel.collector.netty.command.mvb.MvbData;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Date;

/**
 * 务服务-列车信息-调用异常处理
 *
 * @author snps
 * @create 2022-03-11 15:16
 * @describe
 **/
@Component
@Slf4j
public class BusinessTrainServiceFallbackFactory implements FallbackFactory<BusinessTrainService> {

    @Override
    public BusinessTrainService create(Throwable cause) {
        log.error("长连接协议服务，调用失败：{}", cause.getMessage());

        return new BusinessTrainService() {
            /**
             * 修改设备信息
             */
            @Override
            public AjaxResult update(@RequestBody Equipment entity) {
                return AjaxResult.error("修改设备信息，异常！");
            }

            /**
             * 通过mac地址修改设备信息
             */
            public AjaxResult updateByMacAddr(@RequestBody Equipment entity) {
                return AjaxResult.error("通过mac地址修改设备信息，异常！");
            }

            /**
             * 修改网络状态
             */
            @Override
            public AjaxResult setNetStatus(@RequestParam("equipmentMacAddr") String equipmentMacAddr,
                                              @RequestParam("netStatus") Integer netStatus, @Param("version") String version) {
                return AjaxResult.error("修改网络状态，异常！");
            }

            /**
             * 设置全部设备为离线状态
             */
            @Override
            public AjaxResult setAllOffLine() {
                return AjaxResult.error("设置全部设备为离线状态，异常！");
            }

            /**
             * 保存重启日志
             */
            public AjaxResult saveRestartLogs(@RequestParam(value="equipmentMacAddr") String equipmentMacAddr,
                                              @RequestParam(value="datetime") Date datetime, @RequestParam(value="result") Integer result) {
                return AjaxResult.error("保存重启日志，异常！");
            }

            /**
             * 保存自检模式上报数据
             */
            @Override
            public AjaxResult saveCheckData(@RequestBody CheckData entity) {
                return AjaxResult.error("保存自检模式上报数据，异常！");
            }

            /**
             * 保存MVB上报数据
             */
            public AjaxResult saveMvbData(@RequestBody MvbData entity) {
                return AjaxResult.error("保存MVB上报数据，异常！");
            }


        };
    }
}